
package com.edroid.autorunner;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.FragmentManager;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;

import com.edroid.apkhooker.R;

public class SettingsDialog extends DialogFragment implements DialogInterface.OnClickListener {
    private View mView;
    private CheckBox checkBoxAid,checkBoxSid,checkBoxSsid,checkBoxBssid,checkBoxAutoInstall, checkBoxNum;

    
    @SuppressLint("InflateParams")
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater inflater = LayoutInflater.from(getActivity());
        mView = inflater.inflate(R.layout.dialog_settings, null);
        
        checkBoxAid = ((CheckBox) mView.findViewById(R.id.checkBoxAid));
        checkBoxSid = ((CheckBox) mView.findViewById(R.id.checkBoxSid));
        checkBoxSsid = ((CheckBox) mView.findViewById(R.id.checkBoxSsid));
        checkBoxBssid = ((CheckBox) mView.findViewById(R.id.checkBoxBssid));
        checkBoxAutoInstall = ((CheckBox) mView.findViewById(R.id.checkBoxAutoInstall));
        checkBoxNum = ((CheckBox) mView.findViewById(R.id.checkBoxNum));
        
        checkBoxAid.setChecked(Statics.changeAid);
        checkBoxSid.setChecked(Statics.changeSid);
        checkBoxSsid.setChecked(Statics.changeSsid);
        checkBoxBssid.setChecked(Statics.changeBsid);
        checkBoxAutoInstall.setChecked(Statics.autoInstall);
        checkBoxNum.setChecked(Statics.makeNumber);
        ((CheckBox) mView.findViewById(R.id.checkBoxIp)).setChecked(Statics.hookLocalIp);
        ((CheckBox) mView.findViewById(R.id.checkBoxLoc)).setChecked(Statics.hookLocation);

        return new AlertDialog.Builder(getActivity())
                .setView(mView)
                .setPositiveButton(R.string.ok, this)
                .create();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        Statics.changeAid = ((CheckBox) mView.findViewById(R.id.checkBoxAid)).isChecked();
        Statics.changeSid = ((CheckBox) mView.findViewById(R.id.checkBoxSid)).isChecked();
        Statics.changeSsid = ((CheckBox) mView.findViewById(R.id.checkBoxSsid)).isChecked();
        Statics.changeBsid = ((CheckBox) mView.findViewById(R.id.checkBoxBssid)).isChecked();
        Statics.autoInstall = ((CheckBox) mView.findViewById(R.id.checkBoxAutoInstall)).isChecked();
        Statics.makeNumber = checkBoxNum.isChecked();
        Statics.hookLocalIp = ((CheckBox) mView.findViewById(R.id.checkBoxIp)).isChecked();
        Statics.hookLocation = ((CheckBox) mView.findViewById(R.id.checkBoxLoc)).isChecked();
        
        Statics.save();
    }
    
    public static void show(FragmentManager fm) {
        new SettingsDialog().show(fm, "SettingsDialog");
    }
}
